<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BaseTemplateMaster.class.php';

Class TemplateMaster {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjTemplateMaster = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objTemplateMaster = new BaseTemplateMaster();
			$objTemplateMaster->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objTemplateMaster->setName( ( true == isset( $row["name"] ) ) ? $row["name"] : 'NULL' );
			$objTemplateMaster->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objTemplateMaster->setData( ( true == isset( $row["data"] ) ) ? $row["data"] : 'NULL' );
			$objTemplateMaster->setTemplateTypeId( ( true == isset( $row["template_type_id"] ) ) ? $row["template_type_id"] : 'NULL' );
			$objTemplateMaster->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objTemplateMaster->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objTemplateMaster->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objTemplateMaster->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjTemplateMaster, $objTemplateMaster );
		}
		return $arrobjTemplateMaster;
	}
	public function fetchAllTemplateMaster() {
		$result = $this->connection->RunQuery("SELECT * FROM TEMPLATE_MASTERS");
		$arrobjTemplateMaster = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objTemplateMaster = new BaseTemplateMaster();
			$objTemplateMaster->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objTemplateMaster->setName( ( true == isset( $row["name"] ) ) ? $row["name"] : 'NULL' );
			$objTemplateMaster->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objTemplateMaster->setData( ( true == isset( $row["data"] ) ) ? $row["data"] : 'NULL' );
			$objTemplateMaster->setTemplateTypeId( ( true == isset( $row["template_type_id"] ) ) ? $row["template_type_id"] : 'NULL' );
			$objTemplateMaster->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objTemplateMaster->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objTemplateMaster->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objTemplateMaster->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjTemplateMaster, $objTemplateMaster);
		}
		return $arrobjTemplateMaster;
	}
	public function fetchAllTemplateMasterByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM TEMPLATE_MASTERS WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjTemplateMaster = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objTemplateMaster->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objTemplateMaster->setName( ( true == isset( $row["name"] ) ) ? $row["name"] : 'NULL' );
			$objTemplateMaster->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objTemplateMaster->setData( ( true == isset( $row["data"] ) ) ? $row["data"] : 'NULL' );
			$objTemplateMaster->setTemplateTypeId( ( true == isset( $row["template_type_id"] ) ) ? $row["template_type_id"] : 'NULL' );
			$objTemplateMaster->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objTemplateMaster->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objTemplateMaster->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objTemplateMaster->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjTemplateMaster, $objTemplateMaster );
		}
		return $arrobjTemplateMaster;
	}

	public function fetchTemplateMasterById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM TEMPLATE_MASTERS WHERE id = " . $intId );
			$objTemplateMaster = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objTemplateMaster = new BaseTemplateMaster();
			$objTemplateMaster->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objTemplateMaster->setName( ( true == isset( $row["name"] ) ) ? $row["name"] : 'NULL' );
			$objTemplateMaster->setDescription( ( true == isset( $row["description"] ) ) ? $row["description"] : 'NULL' );
			$objTemplateMaster->setData( ( true == isset( $row["data"] ) ) ? $row["data"] : 'NULL' );
			$objTemplateMaster->setTemplateTypeId( ( true == isset( $row["template_type_id"] ) ) ? $row["template_type_id"] : 'NULL' );
			$objTemplateMaster->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objTemplateMaster->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objTemplateMaster->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objTemplateMaster->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
		}
		return $objTemplateMaster;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from template_master order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endTemplateMaster(){
		$this->connection->CloseMysql();
	}

}